/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package client;

/**
 *
 * @author caos
 */
public class EntropyCalculator {
    static int counter[] = { 10, 26, 26, 32};
    static final int MAX_LEN=32;
    private static int getCorrespondentIndex(Character c)
    {
       if(c.isDigit(c)) return 0;
       else if(c.isLetter(c))
           if(c.isLowerCase(c))
               return 1;
           else
               return 2;
       else
           return 3;
    }
    
    static double getMax()
    {
        int t=0;
        for(int i=0; i < counter.length;i++)
            t+=counter[i];
        return MAX_LEN*Math.log(t)/Math.log(2);
    }
    static double getEntropy(String password)
    {
        int tot=0;
        boolean used[]={false, false, false, false};
        for(int i=0; i < password.length(); i++)
        {
            int index=getCorrespondentIndex(password.charAt(i));
            if(!used[index])
            {
                tot+=counter[index];
                used[index]=true;
            }
        }
        return password.length()*Math.log(tot)/Math.log(2);
    }
}
